﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShieldManager : MonoBehaviour {
	private List<GameObject> shieldList;

	/// <summary>
	/// Awake is called when the script instance is being loaded.
	/// </summary>
	void Awake()
	{
		shieldList = new List<GameObject>();
	}

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if(shieldList.Count > 0)
		{
			ControllShield();
		}
	}

	public void AddShield(GameObject shield)
	{
		shieldList.Add(shield);
	}

	private void ControllShield()
	{
		for (int i = 0; i < shieldList.Count; i++)
		{
			if(i == GetFirstShield())
			{
				if(shieldList[i] != null)
				{
					// shieldList[i].GetComponent<CircleCollider2D>().isTrigger = true;
					shieldList[i].active = true;					
				}
				
			}
			else
			{
				if(shieldList[i] != null)
				{
					// shieldList[i].GetComponent<CircleCollider2D>().isTrigger = false;
					shieldList[i].active = false;
				}
			}
		}
	}

	private int GetFirstShield()
	{
		for (int i = 0; i < shieldList.Count; i++)
		{
			if(shieldList[i] != null)
			{
				return i;
			}
		}
		return 0;
	}
}
